#!/usr/bin/env python
from fastapi import FastAPI
from langchain.prompts import ChatPromptTemplate
from langchain_community.chat_models import ChatAnthropic

from langchain_google_genai import ChatGoogleGenerativeAI
from langserve import add_routes

llm = ChatGoogleGenerativeAI(model="models/gemini-1.5-pro-latest", temperature=0.7)
app = FastAPI(
    title="LangChain Server",
    version="1.0",
    description="A simple api server using Langchain's Runnable interfaces",
)

add_routes(
    app,
    llm,
    path="/openai",
)


prompt = ChatPromptTemplate.from_template("给我写首诗关于{topic}")
add_routes(
    app,
    prompt | llm,
    path="/joke",
)


@app.get("/demo")
async def root():
    return {"message": "Hello World"}


if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="localhost", port=8000)